import json
import os
from pathlib import Path

def create_empty_coco_dataset():
    """Create empty COCO format annotation files for OPCOCO dataset."""
    
    # 使用绝对路径
    base_dir = Path("e:/Projects/OperationTool/Code/MaskDINO/coco/opcoco")
    annotations_dir = base_dir / "annotations"
    annotations_dir.mkdir(parents=True, exist_ok=True)
    
    print(f"Creating directories at: {annotations_dir}")
    
    # 定义类别（根据实际情况调整）
    categories = [
        {"id": 1, "name": "object", "supercategory": "object"}
    ]
    
    # 创建训练集标注文件
    train_ann = {
        "info": {
            "description": "OPCOCO Dataset",
            "version": "1.0",
            "year": 2025,
        },
        "licenses": [],
        "images": [],
        "annotations": [],
        "categories": categories
    }
    
    # 创建验证集标注文件
    val_ann = {
        "info": {
            "description": "OPCOCO Dataset",
            "version": "1.0",
            "year": 2025,
        },
        "licenses": [],
        "images": [],
        "annotations": [],
        "categories": categories
    }
    
    # 保存标注文件
    train_file = annotations_dir / "instances_train.json"
    val_file = annotations_dir / "instances_val.json"
    
    with open(train_file, "w") as f:
        json.dump(train_ann, f, indent=2)
        
    with open(val_file, "w") as f:
        json.dump(val_ann, f, indent=2)
    
    print("Created empty COCO format annotation files:")
    print(f"- {train_file}")
    print(f"- {val_file}")
    
    # 验证文件是否创建成功
    if train_file.exists():
        print(f"Train file exists: {train_file.exists()}")
    else:
        print(f"Train file does not exist")
        
    if val_file.exists():
        print(f"Val file exists: {val_file.exists()}")
    else:
        print(f"Val file does not exist")

if __name__ == "__main__":
    create_empty_coco_dataset()